<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>个人中心</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/templatemo-style.css">
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
	let re = new RegExp("\s?" + "username" + "=([^;]+)(;|$)")
	var username=document.cookie.match(re)[1];
	var arry;
	function getUSER() {
		$.ajax({
            url: "http://localhost:8080/voting-system/getUserId",
            type: "post",
            success:function (data) {
            	arry=data;
            	user_id=arry["UserId"];
            	$.ajax({
                    url: "http://localhost:8080/voting-system/getUser",
                    type: "post",
                    success:function (data) {
                    	$("#name").html(data[0].username);
                    	$("#sex").html(data[0].sex);
                    	$("#age").html(data[0].age);
                    	$("#tel").html(data[0].telephone);
                    },
                    dataType: "json",
                    data:{user_id:user_id}
                });
            },
            dataType: "json",
            data:{username:username}
        });
     }
	function deleteUserPer(){
		$.ajax({
            url: "http://localhost:8080/voting-system/getUserId",
            type: "post",
            success:function (data) {
            	arry=data;
            	user_id=arry["UserId"];
            	$.ajax({
                    url: "http://localhost:8080/voting-system/deleteUser",
                    type: "post",
                    success:function (data) {
                    	if(data.delectItem=false){
                    		alert("删除失败！")
                    	}else{
                    		alert("删除成功！")
                    		window.location.href='../login.html'
                    	}
                    },
                    dataType: "json",
                    data:{user_id:user_id}
                });
            },
            dataType: "json",
            data:{username:username}
        });
	}
</script>
<body id="reportsPage" onload="getUSER()">
	<div class="" id="home">
		<nav class="navbar navbar-expand-xl">
			<div class="container h-100">
				<h1 class="tm-site-title mb-0">个人中心</h1>

				<button class="navbar-toggler ml-auto mr-0" type="button"
					data-toggle="collapse" data-target="#navbarSupportedContent"
					aria-controls="navbarSupportedContent" aria-expanded="false"
					aria-label="Toggle navigation">
					<i class="fas fa-bars tm-nav-icon"></i>
				</button>

				<div class="collapse navbar-collapse" id="navbarSupportedContent">
					<ul class="navbar-nav mx-auto h-100">
						<li class="nav-item"><a class="nav-link" href="result.jsp">
								<i class="fas fa-tachometer-alt"></i> 投票结果 <span class="sr-only">(current)</span>
						</a></li>

						<li class="nav-item"><a class="nav-link" href="vote.html">
								<i class="fas fa-shopping-cart"></i> 学生投票
						</a></li>

						<li class="nav-item"><a class="nav-link active"
							href="personal.html"> <i class="far fa-user"></i> 个人中心
						</a></li>

					</ul>
					<ul class="navbar-nav">
						<li class="nav-item"><a class="nav-link d-block"
							href="../login.html"> <b>退出登录</b>
						</a></li>
					</ul>
				</div>
			</div>
		</nav>
		<div class="container mt-5" style="position: relative; left: 170px;">

			<div class="tm-block-col tm-col-account-settings">
				<div class="tm-bg-primary-dark tm-block tm-block-settings">
					<h2 class="tm-block-title">个人信息</h2>
					<form class="tm-signup-form row">
						<div class="form-group col-lg-6">
							<label for="name">用户名</label> <label name="name"
								class="form-control validate" id="name"></label>
						</div>

						<div class="form-group col-lg-6">
							<label for="password">性别</label> <label name="sex"
								class="form-control validate" id="sex"></label>
						</div>
						<div class="form-group col-lg-6">
							<label for="password2">年龄</label> <label name="age"
								class="form-control validate" id="age"></label>
						</div>
						<div class="form-group col-lg-6">
							<label for="phone">电话</label> <label name="tel"
								class="form-control validate" id="tel"></label>
						</div>
						<div class="col-12">
							<a href="edit-person.html"
								class="btn btn-primary btn-block text-uppercase mb-3">编辑您的个人资料</a>
						</div>
						<div class="col-12">
							<button type="button" onclick="deleteUserPer()"
								class="btn btn-primary btn-block text-uppercase mb-3">
								删除您的账户</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	</div>


</body>
</html>
